'''
Created on Oct 12, 2010
Decision Tree Source Code for Machine Learning in Action Ch. 3
@author: Peter Harrington
'''
from hjdong.ml.ch03 import trees
from hjdong.ml.ch03 import treePlotter
    

fr = open("./../../../data/ch03/lenses.txt")
lenses = [inst.strip().split("\t") for inst in fr]
print(lenses)
lensesLabels=['age', 'prescript', 'astigmatic', 'tearRate']
lensesDeciTree = trees.createTree(lenses, lensesLabels)
print(lensesDeciTree)
treePlotter.createPlot(lensesDeciTree)

# 1>>> fr=open（'lenses.txt’）
# 2>>> lenses=[inst.strip（）.split（'\t'） for inst in fr.readlines（）]
# 3>>> lensesLabels=['age', 'prescript', 'astigmatic', 'tearRate']
# 4>>> lensesTree = trees.createTree（lenses,lensesLabels）
# 5>>> lensesTree
# 6{'tearRate': {'reduced': 'no lenses', 'normal': {'astigmatic': {'yes':
# 7{'prescript': {'hyper': {'age': {'pre': 'no lenses', 'presbyopic':
# 8'no lenses', 'young':'hard'}}, 'myope': 'hard'}}, 'no': {'age': {'pre':
# 9'soft', 'presbyopic': {'prescript': {'hyper': 'soft', 'myope':
# 10'no lenses'}}, 'young': 'soft'}}}}}}
# 11>>> treePlotter.createPlot（lensesTree）
# # 迭代方式构造决策树
# useLabels = labels[:]
# deciTree = createTree(myDat, useLabels)
# print(deciTree)
# 
# # 使用决策树
# resultClass = classify(deciTree, labels, [1,1])
# print(resultClass)
